package com.nuvsoft.android.nuvgamenet;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class GameLobby {
	private String nick;
	private String address;
	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	private long lastContact;
	private View v;
	private static NuvGameNetApplication na;

	/**
	 * Used when starting a new lobby
	 * 
	 * @param host
	 */
	public GameLobby(String lobbyNick, String hostAddress, NuvGameNetApplication na) {
		GameLobby.na = na;
		this.address = hostAddress;
		this.nick = lobbyNick;
	}

	public void updateContact() {
		lastContact = System.currentTimeMillis();
	}

	public long getLastContact() {
		return lastContact;
	}

	public View getListView(Context c) {
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) c
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.lobby_row, null);
		}
		TextView tv_nick = (TextView) v.findViewById(R.id.tv_nick);
		Button b_join = (Button) v.findViewById(R.id.b_join);
		if (tv_nick != null) {
			tv_nick.setText(nick);
		}
		if (b_join != null) {
			b_join.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View arg0) {
					na.getConnectionManager().joinLobby(address);
				}
			});
		}
		return v;
	}
}
